package com.maybach.workflow.core.expression;

import de.odysseus.el.ExpressionFactoryImpl;
import de.odysseus.el.util.SimpleContext;

import java.util.Map;

/**
 * Created by houenxun on 15/8/17.
 */
public class JuelExpression implements IExpression{
    javax.el.ExpressionFactory factory = new ExpressionFactoryImpl();
    @Override
    @SuppressWarnings("unchecked")
    public <T> T eval(Class<T> T, String expr, Map<String, Object> args) {
        SimpleContext context = new SimpleContext();
        for(Map.Entry<String, Object> entry : args.entrySet()) {
            context.setVariable(entry.getKey(), factory.createValueExpression(entry.getValue(), Object.class));
        }
        return (T)factory.createValueExpression(context, expr, T).getValue(context);
    }

}
